<template>
  <div class="page-content padding-top">
    <item class="y-item" style="margin-bottom: 10px;margin-top:10px">
      <span class="item-title">原密码</span>
      <input type="password" class="y-item-input" name="carTitle" v-model="password" placeholder="请输入原密码" required>
    </item>
    <item class="y-item">
      <span class="item-title">新密码</span>
      <input type="password" class="y-item-input" name="carTitle" v-model="newPassword" placeholder="请输入新密码" required>
    </item>
    <item class="y-item" style="margin-bottom: 50px;">
      <span class="item-title">确认密码</span>
      <input type="password" class="y-item-input" name="carTitle" v-model="passwordAgain" placeholder="请再次输入新密码" required>
    </item>
      <div class="outbtn" ><md-button class="button button-assertive button-block" @click.native="updatePass">确认</md-button></div>
  </div>
</template>
<script>
import { bus } from 'bus.js'
  export default {
    data() {
      return {
        password:'',
        newPassword:'',
        passwordAgain:'',
        
      }
    },
    methods: {
      updatePass(){
        if (this.newPassword == '' || this.password == '' || this.passwordAgain == '') {
          $toast.show('密码不能为空！',3000);
          return false;
        }
        if (this.passwordAgain != this.newPassword) {
          $toast.show('两次密码输入不一致！',3000);
          return false;
        }
        var _this = this;
        axios.get(baseUrl+'/controller/updatePwd',{params:{
            accountName:sess.get('userSession').accountName,
            accountPassword:_this.password,
            newPassword:_this.newPassword
          }
        })
        .then(function(res){
          setTimeout(()=>{
            $toast.show(res.data.msg,3000);
          },400)
          _this.password = '';
          _this.newPassword = '';
          _this.passwordAgain = '';
          bus.$emit('password');
        })
      }
    }
  }
</script>
